<template>
	<view>
		<!-- 搜索区域 -->
		<view class="search">
			<my-search></my-search>
		</view>
		<!-- /搜索区域 -->
		<!-- 轮播图 -->
		<swiper :circular="true" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- /轮播图 -->
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" @click="navClickHandle(item)">
				<image :src="item.image_src"></image>
			</view>
		</view>
		<!-- /分类导航 -->
		<!-- 楼层 -->
		<view class="floor">
			<view class="floor-item" v-for="(item, index) in floorList" :key="index">
				<view class="floor_title">
					<image :src="item.floor_title.image_src" mode="widthFix"></image>
				</view>
				<view class="floor_content">
					<view class="left">
						<image :src="item.product_list[0].image_src" mode="widthFix"></image>
					</view>
					<view class="right">
						<view class="imgGroup">
							<image :class="i === 0 || 1 ? 'padding' : ''" :src="img.image_src" v-for="(img, i) in item.product_list" :key="i" v-if="i !== 0"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- /楼层 -->
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbarBadge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const {data} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (data.meta.status !== 200) {
					return uni.showMsg('加载失败')
				}
				this.swiperList = data.message
				console.log(this.swiperList)
			},
			async getNavList() {
				const {data} = await uni.$http.get('/api/public/v1/home/catitems')
				if (data.meta.status !== 200) {
					return uni.showMsg('加载失败')
				}
				this.navList = data.message
				console.log(this.navList)
			},
			navClickHandle(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url: "/pages/cate/cate"
					})
				} else {
					uni.navigateTo({
						url: '/subpkg/cate_detail/cate_detail'
					})
				}
			},
			async getFloorList() {
				const {data} = await uni.$http.get('/api/public/v1/home/floordata')
				if (data.meta.status !== 200) {
					return uni.showMsg('加载失败')
				}
				this.floorList = data.message
				console.log(this.floorList)
			}
		}
	}
</script>

<style lang="scss">
	.search {
		height: 50px;
		position: sticky;
		top:0;
		left:0;
		z-index: 99;
	}
	.padding {
		padding-bottom: 8rpx
	}
	swiper {
		height: 330rpx
	}
	.swiper-item,
	image{
		width: 100%;
		heigth: 100%
	}
	.nav-list {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 20rpx 0;
		.nav-item {
			width: 128rpx;
			height: 140rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
	.floor {
		width: 100%;
		.floor-item {
			width: 100%;
			padding: 20rpx;
			.floor_title {
				width: 100%;
			}
			.floor_content {
				display: flex;
				width: 100%;
				.left {
					flex: 1;
					image {
						width: 233rpx;
					}
				}
				.right {
					flex: 2;
					.imgGroup {
						display: flex;
						flex-wrap: wrap;
						// justify-content: space-around;
						image {
							width: 233rpx;
							height: 191rpx;
							padding-left: 10rpx;
						}
					}
				}
			}
		}
	}
</style>
